package com.phoenix.jsef.basedata.service;

import java.util.List;
import java.util.Map;
import java.io.Serializable;
import com.phoenix.jsef.framework.*;
import com.phoenix.jsef.jdbcutils.CommandType;
import com.phoenix.jsef.basedata.pojo.*;
import com.phoenix.jsef.basedata.shared.*;
import com.phoenix.jsef.basedata.dao.*;
import org.springframework.cache.annotation.*;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @ClassName:  CBizBaseRole
 * @Description:TODO(商业实体对象:CBaseRoleEntity对应提供的服务具体实现)
 * @author: 李启联
 * @date:   2019-8-6 16:41:33
 * @version V1.0
 * @Copyright: Copyright (c) 2018
 * 申明：本内容未经作者本人同意,禁止外泄以及用于其他的商业项目.
 */
@Service
@CacheConfig(cacheNames="BizBaseRole_Cache")
public class CBizBaseRole implements IBizBaseRole {

    @Autowired
    private CBaseRoleRepository access;

    @Override
    @Cacheable()
    public EntityCollection getCollection(Map<String,Object> filter) throws Exception {
        AccessParameter parameter = new AccessParameter();
        parameter.getFilter().addAllEqual(filter);
        return access.searchEntityCollection(parameter);
    }

    @Override
    @Cacheable()
    public List<CBaseRoleEntity> getList(Map<String,Object> filter) throws Exception {
        AccessParameter parameter =  new AccessParameter();
        parameter.getFilter().addAllEqual(filter);
        return (List<CBaseRoleEntity>) access.searchEntityList(parameter);
    }


    @Override
    @Cacheable()
    public List<CBaseRoleEntity> getListBySql(CommandType commandType, String commandText, Object... obj) throws Exception {
        return (List<CBaseRoleEntity>) access.searchEntityListBySQL(commandType,commandText,obj);
    }

    @Override
    @Cacheable(key="#root.targetClass+':'+#root.methodName+':'+#filter+':'+#pageIndex+':'+#pageSize")
    public  PageInfo<CBaseRoleEntity> getPageInfo(Map<String, Object> filter, Map<String, String> sorter,
       Integer pageIndex, Integer pageSize) throws Exception {

        AccessParameter parameter =  new AccessParameter();

        if(null != filter)
        parameter.getFilter().addAllEqual(filter);
        if(null != sorter)
        parameter.getSorter().add(sorter);

        parameter.setPageSize(pageSize);
        parameter.setPageIndex(pageIndex);

        return access.searchEntityPageInfo(parameter);
    }

    @Override
    @Cacheable()
    public PageInfo<CBaseRoleEntity> searchEntityPageInfo(AccessParameter parameter) throws Exception {
        return access.searchEntityPageInfo(parameter);
    }

    @Override
    @Cacheable(key="#id")
    public  CBaseRoleEntity getEntityById(String id) throws Exception {
        AccessParameter parameter = new AccessParameter();
        parameter.getFilter().addEqual(CBaseRoleTags.PrimaryKey,id);
        return (CBaseRoleEntity) access.searchEntity(parameter);
    }

    @Override
    @Cacheable()
    public List<CBaseRoleEntity> getEntityListByIds(List<? extends Serializable> ids) throws Exception {
        return (List<CBaseRoleEntity>) access.searchEntityListByIds(ids);
    }

    @Override
    public Map<String, Object> getMapById(String id) throws Exception {
        return access.getMapById(id);
    }

    @Override
    public boolean insert(CBaseRoleEntity entity) throws Exception {
    return access.insert(entity);
    }

    @Override
    public boolean update(CBaseRoleEntity entity) throws Exception {
        return access.update(entity);
    }

    @Override
    public boolean updateWithSelective(CBaseRoleEntity entity) throws Exception {
        return access.updateWithSelective(entity);
    }

    @Override
    public boolean delete(CBaseRoleEntity entity) throws Exception {
        return access.delete(entity);
    }

    @Override
    public boolean deleteByIdForSingle(Object keyValue) throws Exception {
        return access.deleteByIdForSingle(keyValue);
    }

    @Override
    public boolean deleteBatchIds(List<? extends Serializable> ids, boolean recursive) throws Exception {
        return access.deleteBatchIds(ids,recursive);
    }

    @Override
    public boolean deleteBatchIds(List<? extends Serializable> ids) throws Exception {
        return deleteBatchIds(ids,true);
    }

}